package com.example.bookstore.controller;

import com.example.bookstore.form.noticeform.InsertNoticeForm;
import com.example.bookstore.form.orderform.InsertOrderForm;
import com.example.bookstore.service.OrderService;
import com.example.bookstore.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@Slf4j
@Api(value = "用户操作接口", tags = {"订单管理"})
@RestController
@RequestMapping("/OrderController")
public class OrderController {

    @Autowired
    OrderService orderService;

    @ApiOperation("创建一个新的订单")
    @PostMapping("/InsertOrder")
    public ResultVO InsertOrder(InsertOrderForm insertOrderForm) throws ParseException {
        return orderService.InsertOrder(insertOrderForm);
    }

    @ApiOperation("根据id删除一个订单")
    @PostMapping("/DeleteOrder")
    public ResultVO DeleteOrder(Integer orderId) {
        return orderService.DeleteOrder(orderId);
    }

    @ApiOperation("更新支付状态信息")
    @PostMapping("/UpdatePayState")
    public ResultVO UpdatePayState(Integer orderId) {
        return orderService.UpdatePayState(orderId);
    }

    @ApiOperation("精确查询某次订单")
    @PostMapping("/SelectOrderById")
    public ResultVO SelectOrderById(Integer orderId) {
        return orderService.SelectOrderById(orderId);
    }

    @ApiOperation("根据某个用户查询他所有的订单")
    @PostMapping("/SelectOrderByUser")
    public ResultVO SelectOrderByUser(Integer userId) {
        return orderService.SelectOrderByUser(userId);
    }

    @ApiOperation("从高到低，返回本周销量的书本信息")
    @PostMapping("/ShowAllOrderByWeek")
    public ResultVO ShowAllOrderByWeek() {
        return orderService.ShowAllOrderByWeek();
    }

}
